/*
 *
 *  This file is part of Cfu
 *
 *  Cfu is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  Cfu is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with Cfu. If not, see <http://www.gnu.org/licenses/>.
 *
 *  parser.hpp - william le ferrand (william@corefarm.com) 29/04/2010 15:30
 *
 */


#ifndef PARSER_HPP_
#define PARSER_HPP_

#include <string>
#include <list>
#include <vector>

#include <connector.hpp>
#include <mainwindow.hpp>

struct checker 
{
  int status ; 
  const char *msg; 

  bool upload ; 
  std::string *job_id; 
  std::string *server; 
  std::string *login;
  std::string *password; 
  mainwindow_t *mainWindow; 
};

class xmlParser_t;

bool check_filenames(const char *filename, struct checker *chk);

typedef void (*startElement_cb)(xmlParser_t &p, const char *element, const char **attrs);
typedef void (*endElement_cb)(xmlParser_t &p, const char *element);

struct parserState_t
{
	startElement_cb start;
	endElement_cb end;
	void *userdata;
	int level;
};

class xmlParser_t
{
public:
  xmlParser_t(struct checker *chk);
  void pushState(startElement_cb start, endElement_cb end, void *userdata=0);
  void popState();
  void startElement(const char *element, const char **attrs){ ++level; if(current) current->start(*this, element, attrs); }
  void endElement(const char *element)	{ if(current) current->end(*this, element); --level; }
  void* stateData(){ return current->userdata; }
  //	void setParam(const std::string &name, parameter_t &param){ (*cparams)[name] = param; }
  int currLevel() const{ return level; }
  int stateLevel() const { return current ? current->level : -1; }
  struct checker *_chk; 

protected:
  std::vector<parserState_t> state_stack;
  parserState_t *current;
  int level;

};

// state callbacks:
void startEl_document(xmlParser_t &p, const char *element, const char **attrs);
void endEl_document(xmlParser_t &p, const char *element);
void startEl_scene(xmlParser_t &p, const char *element, const char **attrs);
void endEl_scene(xmlParser_t &p, const char *element);
void startEl_mesh(xmlParser_t &p, const char *element, const char **attrs);
void endEl_mesh(xmlParser_t &p, const char *element);
void startEl_parammap(xmlParser_t &p, const char *element, const char **attrs);
void endEl_parammap(xmlParser_t &p, const char *element);
void startEl_paramlist(xmlParser_t &p, const char *element, const char **attrs);
void endEl_paramlist(xmlParser_t &p, const char *element);
void endEl_render(xmlParser_t &p, const char *element);

#endif
